package com.prs.crm.action;

import java.util.Collection;
import java.util.Map;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.XJAction;
import com.prs.crm.context.AppContext;
import com.prs.crm.domain.sys.Menu;
import com.prs.crm.service.sys.MenuService;
public class HomeAction extends XJAction{

	private static final long serialVersionUID = 6360912927256149488L;
	
	private MenuService menuService;
	 private String rowdata;
	
	private Collection<Menu> menus;
	private Map<String,Menu> purviews;
	
	private Menu menu;
	private  String titles;
	
	public void setMenuService(MenuService menuService) {
		this.menuService = menuService;
	}

	public MenuService getMenuService() {
		return menuService;
	}

	public void setPurviews(Map<String,Menu> purviews) {
		this.purviews = purviews;
	}

	public Map<String,Menu> getPurviews() {
		return purviews;
	}

	public void setMenus(Collection<Menu> menus) {
		this.menus = menus;
	}

	public Collection<Menu> getMenus() {
		return menus;
	}

	public void setMenu(Menu menu) {
		this.menu = menu;
	}

	public Menu getMenu() {
		return menu;
	}

	@Action("home")
	public String execute()
	{
		
		
		return SUCCESS;
	}
	
	@Action("head")
	public String head()
	{

		 menus = getMenuService().findMenus(null, AppContext.getAccountContext().currentUser());
     
		 
		 
		return SUCCESS;
	}
	
	@Action(value = "candleAjax", results = { @Result(name = "success", type = "json", params = {
			"root", "rowdata" }) })
	public String candleAjax() {
     

	
		
		
		return SUCCESS;
	}

	@SuppressWarnings("unchecked")
	@Action("left")
	public String left()
	{
		if (menu==null)
		{
			menu = this.getMenuService().getRootMenus().get(0);
			
		}
		if (AppContext.getAccountContext()!=null)
		{
			menus = this.getMenuService().findMenus(menu, AppContext.getAccountContext().currentUser());
		}
		else
		{
			menus = menu.getChilds();
		}
		this.setPurviews((Map<String,Menu>)this.getStorage().get("com.prs.crm.store.role"));
		return SUCCESS;
	}

	

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	

	public String getRowdata() {
		return rowdata;
	}

	public void setRowdata(String rowdata) {
		this.rowdata = rowdata;
	}

	public String getTitles() {
		return titles;
	}

	public void setTitles(String titles) {
		this.titles = titles;
	}
	
	
}
